//
//  BaseNoDate.m
//  YYBG_IOS
//
//  Created by wyl on 2017/5/12.
//  Copyright © 2017年 wyl. All rights reserved.
//

#import "BaseNoDate.h"
#import "Masonry.h"
#import "BSCommon.h"
#import "AppDelegate.h"

@interface BaseNoDate ()<UIScrollViewDelegate>

@property (nonatomic,strong) UIImageView *imageView;
@property (nonatomic,strong) UILabel *topLabel;
@property (nonatomic,strong) UILabel *bottomLabel;

@end


@implementation BaseNoDate

#pragma mark - 构造方法

- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        // UI搭建
        [self setUpUI];
    }
    return self;
}

#pragma mark - UI搭建
/** UI搭建 */
- (void)setUpUI{
    self.backgroundColor = [UIColor whiteColor];
    
    //------- 图片 -------//
    self.imageView = [[UIImageView alloc]init];
    [self addSubview:self.imageView];
    
    //------- 内容描述 -------//
    self.topLabel = [[UILabel alloc]init];
    [self addSubview:self.topLabel];
    self.topLabel.textAlignment = NSTextAlignmentCenter;
    self.topLabel.font = [UIFont systemFontOfSize:15];
    self.topLabel.textColor = [UIColor colorWithHexString:COLOR_FONT_LIGHT_GRAY];
    self.topLabel.numberOfLines =2 ;
    
    //------- 提示点击重新加载 -------//
    self.bottomLabel = [[UILabel alloc]init];
    [self addSubview:self.bottomLabel];
    self.bottomLabel.textAlignment = NSTextAlignmentCenter;
    self.bottomLabel.font = [UIFont systemFontOfSize:15];
    self.bottomLabel.textColor = [UIColor colorWithHexString:@"484848"];
    self.bottomLabel.userInteractionEnabled =NO ;
    
    //------- 建立约束 -------//
    [self.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self);
        make.centerY.mas_offset(-100);
        make.size.mas_equalTo(CGSizeMake(200, 100));
    }];
    
    [self.topLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.imageView.mas_bottom).mas_offset(10);
        make.left.right.mas_offset(0);
        make.height.mas_equalTo(40);
    }];
    
    [self.bottomLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.topLabel.mas_bottom).mas_offset(5);
        make.centerX.mas_equalTo(self);
        make.height.mas_equalTo(25);
        make.width.mas_equalTo(95) ;
    }];
    
}


#pragma mark - 根据传入的值创建相应的UI
/** 无数据占位图的类型 */
-(void)setTypeAndTitle:(NoContentType)type title:(NSString *)title{
    switch (type) {
            
        case NoContentTypeNetwork: // 没网
        {
        [self setImage:ImageNamed(@"blank_no_network")  topLabelText:@"主银，您的网络不给力哦～" bottomLabelText:@"点击重试"];
        }
            break;
            
        case NoContentTypeNoDate:
        {
            [self setImage:ImageNamed(@"blank_no_data")  topLabelText:title bottomLabelText:@""];
        }
            break;
           
        case NoContentTypeNoCart:
        {
            [self setImage:ImageNamed(@"blank_cart_no")  topLabelText:@"主银，您的购物车还是空的哦～" bottomLabelText:@""];
        }
            break;
        case NoContentTypeNoPost:
        {
            [self setImage:ImageNamed(@"blank_no_post")  topLabelText:@"暂时还没有晒单哦～" bottomLabelText:@""];
        }
            break;
        case NoContentTypeNoWin:
        {
            [self setImage:ImageNamed(@"blank_obtain_goods")  topLabelText:@"最近三个月无记录" bottomLabelText:@"立即必购"];
        }
            break;
        case NoContentTypeNoBuy:
        {
            [self setImage:ImageNamed(@"blank_no_commodity_no")  topLabelText:@"还没参与必购？\n梦想与您只有1元的距离" bottomLabelText:@"立即必购"];
        }
            break;
        case NoContentTypeNoSearch:
        {
            [self setImage:ImageNamed(@"blank_obtain_goods")  topLabelText:@"抱歉，没有找到相关商品" bottomLabelText:@""];
        }
            break;
            
        case NoContentTypeNoMessage:
        {
            [self setImage:ImageNamed(@"blank_message")  topLabelText:@"主银，没有系统通知哦！" bottomLabelText:@""];
        }
            break;
        default:
            break;
    }
}

#pragma mark - 设置图片和文字
/** 设置图片和文字 */
- (void)setImage:(UIImage *)image topLabelText:(NSString *)topLabelText bottomLabelText:(NSString *)bottomLabelText{
    self.imageView.image =image;
    self.topLabel.text = topLabelText;
    if (bottomLabelText && ![bottomLabelText isEqualToString:@""]) {
        self.bottomLabel .hidden = NO ;
        self.bottomLabel.text = bottomLabelText;
        self.bottomLabel.textColor =[UIColor orangeColor];
        [self.bottomLabel setBorder:1 cornerRadius:12.5];
        self.bottomLabel.layer.borderColor = [[UIColor orangeColor]CGColor];
        
        if (![bottomLabelText isEqualToString:@"点击重试"]) {
            self.bottomLabel.userInteractionEnabled = YES ;
            UITapGestureRecognizer*tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(goToMain)];
            [self.bottomLabel addGestureRecognizer:tapGesture];
        } 
    }else {
        self.bottomLabel .hidden = YES ;
    }
}

-(void)goToMain{
    
//     [(AppDelegate*)[UIApplication sharedApplication].delegate toMain] ;
}
@end
